/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-09-14
 * Time: 22:16
 */
public class Test {
    public int[] searchRange(int[] nums, int target) {
        int start = binarySearch1(nums,target);
        if(start == nums.length || nums[start] != target){
            return new int[]{-1,-1};
        }
        int end = binarySearch1(nums,target + 1) - 1;
        return new int[]{start,end};
    }
    //闭区间
    // public int binarySearch(int[] nums, int target){
    //     int left = 0;
    //     int right = nums.length - 1;
    //     while(left <= right){
    //         int mid = left + (right - left) / 2;
    //         if(target > nums[mid]){//[mid + 1, rght]
    //             left = mid + 1;
    //         }else{//[left,mid - 1]
    //             right = mid - 1;
    //         }
    //     }
    //     return left;
    // }
    //左闭右开
    public int binarySearch1(int[] nums, int target){
        int left = 0;
        int right = nums.length;
        while(left < right){
            int mid = left + (right - left) / 2;
            if(target > nums[mid]){//[mid + 1, rght]
                left = mid + 1;
            }else{//[left,mid - 1]
                right = mid;
            }
        }
        return left;
    }
}
